﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Web.Configuration;

namespace comix
{
    public partial class sq : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();


            SqlConnection con = new SqlConnection();
            con.ConnectionString = WebConfigurationManager.ConnectionStrings["mainconectionstring"].ConnectionString;
            SqlCommand com = new SqlCommand(TextBox1.Text, con);
            con.Open();
            try
            {
                SqlDataReader rdr = com.ExecuteReader();
                if (rdr.HasRows)
                {
                    TableHeaderRow hr = new TableHeaderRow();
                    for (int i = 0; i < rdr.FieldCount; i++)
                    {
                        TableHeaderCell hc = new TableHeaderCell();
                        hc.Text = rdr.GetName(i);
                        hr.Cells.Add(hc);
                    }
                    Table1.Rows.Add(hr);
                    while (rdr.Read())
                    {
                        TableRow tr = new TableRow();
                        for (int i = 0; i < rdr.FieldCount; i++)
                        {
                            TableCell tc = new TableCell();
                            tc.Text = rdr.GetValue(i).ToString();
                            tr.Cells.Add(tc);

                            string s = tc.Text.Replace("\r\n", "");

                        }

                        Table1.Rows.Add(tr);
                    }

                }
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
            finally
            {
                con.Close();
            }

        }
    }
}
